#! /usr/bin/env python
# -*- coding: utf-8 -*-
import os
# 将文件夹中的文件 合并到一个文件，软著要源代码的情况
path = "D:/ProjectGys/App/Phone/app/src/main/java";
maxLines = 8000;
if __name__ == '__main__':
    filePath = os.path.join(path, "code.txt");
    with open(filePath, mode='w', encoding="utf-8") as file:
        _lineNum = 0
        for root, dirs, files in os.walk(path, topdown=False):
            if _lineNum >= maxLines:
                break
            for name in files:
                if _lineNum >= maxLines:
                    break
                with open(os.path.join(root, name), mode="r", encoding="utf-8") as _file:
                    _lines = _file.readlines()
                    _lineNum += len(_lines)
                    file.writelines(_lines)
